package com.example.newbilityblog.blog.domain.entity;

import com.example.newbilityblog.blog.domain.command.CreateBlogCommand;
import com.example.newbilityblog.blog.domain.command.UpdateBlogCommand;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.Instant;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Blog {
    private Long id;
    private String title;
    private String author;
    private String coverImage;
    private String content;
    private String sourceMarkDownContent;
    private String status;
    private Long views;
    private Boolean enableComment;
    private Instant createdDate;

    public void update(UpdateBlogCommand command) {
        this.title = command.getTitle();
//        this.author = command.getAuthor();
        this.coverImage = command.getCoverImage();
        this.content = command.getContent();
        this.sourceMarkDownContent = command.getSourceMarkDownContent();
        this.status = command.getStatus();
//        this.views = command.getViews();
        this.enableComment = command.getEnableComment();
//        this.createdDate = command.getCreatedDate();
    }

    public void create(CreateBlogCommand command) {
        this.id = ThreadLocalRandom.current().nextLong(10000000000L);
        this.title = command.getTitle();
        this.author = "包子哥";
        this.coverImage = command.getCoverImage();
        this.content = command.getContent();
        this.sourceMarkDownContent = command.getSourceMarkDownContent();
        this.status = command.getStatus();
        this.views = 0L;
        this.enableComment = command.getEnableComment();
        this.createdDate = Instant.now();
    }
}
